<?php

class OrderService
{
	protected $model;

	public function __construct(Order $order)
	{
		$this->model = $order;
	}

	public function createOrder($order_type, $product_id, $price, $user_id, $state, $title, $phone = '', $qty = 1, $workflow_id = 0, $pay_status = 0)
	{
//		$order = $this->model;
//		$order->user_id = $user_id;
//		$order->price = $price;
//		$order->title = $title;
//		$order->phone = $phone;
//		$order->qty = $qty;
//		$order->workflow_id = $workflow_id;
//		$order->state = $state;
//		$order->pay_status = $pay_status;
//		$order->order_type = $order_type;
//		$order->product_id = $product_id;
//		$order->save();
//		return $order;
		return $this->model->create([
			'user_id'     => $user_id,
			'price'       => $price,
			'title'       => $title,
			'phone'       => $phone,
			'qty'         => $qty,
			'workflow_id' => $workflow_id,
			'state'       => $state,
			'pay_status'  => $pay_status,
			'order_type'  => $order_type,
			'product_id'  => $product_id,
		]);
	}

	public function getOrderById($id)
	{
		return $this->model->select('id', 'price', 'product_id', 'order_no', 'order_type')->find($id);
	}
}